package mac5855.app.dao;

//Cloudscape concrete DAO Factory implementation
import java.sql.*;

public class JdbcDAOFactory extends DAOFactory {
	public static final String DRIVER=
		"com.mysql.jdbc.Driver";
	public static final String DBURL=
		"jdbc:mysql://pcgerosa.ime.usp.br/sistemaperguntaresposta";


	// method to create Jdbc connections
	public static Connection createConnection() {
		// Use DRIVER and DBURL to create a connection
		// Recommend connection pool implementation/usage
		Connection conn = null;
		try
		{
			String userName = "marcio";
			String password = "perguntas";
			String url = DBURL;
			Class.forName (DRIVER).newInstance ();
			conn = DriverManager.getConnection (url, userName, password);
			System.out.println ("Database connection established");
		}
		catch (Exception e)
		{
			System.err.println ("Cannot connect to database server");
		}

		return conn;
	}

	public static void releaseConnection(Connection conn) {
		if (conn != null)
		{
			try
			{
				conn.close ();
				System.out.println ("Database connection terminated");
			}
			catch (Exception e) { /* ignore close errors */ }
		}
	}

	public PerguntaDAO getPerguntaDAO() {
		return new JdbcPerguntaDAO();
	}
	public RespostaDAO getRespostaDAO() {
		// CloudscapeAccountDAO implements AccountDAO
		return new JdbcRespostaDAO();
	}
	public CategoriaDAO getCategoriaDAO() {
		// CloudscapeOrderDAO implements OrderDAO
		return new JdbcCategoriaDAO();
	}

	public UsuarioDAO getUsuarioDAO() {
		// CloudscapeOrderDAO implements OrderDAO
		return new JdbcUsuarioDAO();
	}
	
	public DenunciaDAO getDenunciaDAO() {
		// CloudscapeOrderDAO implements OrderDAO
		return new JdbcDenunciaDAO();
	}
	

}